<?php
// News class


class Register extends Controller {
    var $user_session_id;
    function Register()
    {
        parent::Controller();
	//$this->output->enable_profiler(TRUE);

		//$this->config->load('facebook');
        $this->load->helper(array('form','tiap_helper','html'));
        $this->load->library(array('form_validation','session'));
       // $this->load->model('Directory_company_model');
        // $this->load->library('Session');
       $this->load->model(array('Directory_user_model', 'Settings_model','Directory_services_model',
            'Directory_company_model', 'Directory_photo_model','Directory_invoice_model','packages_model'));
       // $this->check_session();
    }
    
    
function index(){

                     if($this->input->post('submit'))
		{ 
                        $this->form_validation->set_error_delimiters('<div class="error">','</div>');

                        $this->form_validation->set_rules('name','name','required|trim|xss_clean');
			
			$this->form_validation->set_rules('telephone','telephone','required|trim|xss_clean');
			$this->form_validation->set_rules('email','email','required|trim|xss_clean|valid_email');

			$this->form_validation->set_message('required', 'Please input %s');

			$this->form_validation->set_message('valid_email', 'Please input valid %s address');

			if ($this->form_validation->run() == TRUE)
			{ 
			    $data['name'] = $this->input->post('name');
				
				$data['email'] = $this->input->post('email');
				$data['telephone'] = $this->input->post('telephone');


                $company['name'] = $this->input->post('name');
               
                $company['telephone'] = $this->input->post('telephone');
                $company['email'] = $this->input->post('email');
                    
                 $this->session->set_userdata('name',$this->input->post('name'));
                $this->session->set_userdata('email',$this->input->post('email'));
                $this->session->set_userdata('telephone',$this->input->post('telephone'));
                $this->session->set_userdata('user_info', $company);
                redirect('/register/packages/');
                
			}
			else
			{ 

         $data['name'] =  $name;
        
	$data['email'] =  $email;
	$data['telephone'] =  $telephone;

                $this->load->view(TEMPLATE_NAME."/front/register/signup",$data);
			}

		} else{
               
                 $this->load->view(TEMPLATE_NAME.'/front/register/signup',$data);
                        }
	}

function packages(){  //print_r($this->session->userdata('user_info'));
   // print_r($this->session->userdata('user_info'));exit;
 /* if(!$this->session->userdata('user_info')){
           redirect('register');  
        }*/
  $this->load->model('register_model');
           if($this->input->post('submit_pack'))
		{
                     $package = $this->input->post('package');
                    if($package !='')
                    {
                        $this->session->set_userdata('packages', $package);
                       
                       redirect('register/rules_and_regulation');
                    }

                    
                /*$this->form_validation->set_error_delimiters('<div class="error">','</div>');
                $this->form_validation->set_rules('package','package','required|trim|xss_clean');
                // $this->form_validation->set_rules('payment_type','payment_type','required|trim|xss_clean');
                $this->form_validation->set_message('required', 'Please input %s');
                    if ($this->form_validation->run() == TRUE)
                    {
                      $package = $this->input->post('package');

                      $this->session->set_userdata('package',$data['package']);*/
                      
               
             }else{

                 $this->load->view(TEMPLATE_NAME."/front/register/packages",$data);
             }
  
}

function rules_and_regulation()	//for news location step
	{ 
	  // print_r( $this->session->userdata('packages'));die();
      
      
	    $submit_button = $this->input->post('submit_term');
            if($submit_button != ""){
			if($this->session->userdata('step') != '6')
			{
				$this->session->set_userdata('step', 3);
			}

			$this->form_validation->set_rules('agreed', 'agreed','required');
			if($this->form_validation->run() == true) {
                            $agreed = $this->input->post('agreed');
                            if($agreed)
                            {
                                $this->session->set_userdata('rules_and_regulation',true);
                                redirect('register/login_information');
                            }
			
                        }else{
                        $this->load->view(TEMPLATE_NAME.'/front/register/rules_and_regulation',$data);
                        }
                }else{
                  $this->load->view(TEMPLATE_NAME.'/front/register/rules_and_regulation',$data);
                }
 

	}

	function login_information()
	{ //print_r($this->session->userdata('rules_and_regulation'));
	   //print_r($this->session->userdata('user_info'));
               $data = array();
	  //$data['services_list'] = $this->Directory_services_model->get_list_services("services");
      $submit_button = $this->input->post('submit');
      if($submit_button !== "")
      {
        	$form_re_email = $this->input->post('re_email');
        	$form_email = $this->input->post('email');
        	$form_password = $this->input->post('password');
        	//$this->directory_user_email = $this->input->post('email');;
        	//$this->directory_user_password = $this->input->post('password');

           // $this->form_validation->set_rules('recaptcha_response_field', 'Captcha field', 'callback_check_captcha');
         //	$this->form_validation->set_rules('email', 'Email ', 'required|valid_email|callback_check_email');
         	$this->form_validation->set_rules('re_email', 'Email Confirmation', 'required|valid_email|matches[email]');
                $this->form_validation->set_rules('password', 'Password','required|min_length[6]');
                $this->form_validation->set_rules('re_password', 'Password confirmation','required|min_length[6]|matches[password]');
        	if($this->form_validation->run() == TRUE)
            {
                 //$directory_user_id = $this->Directory_company_model->register_user($form_email, $form_password);
                 //$this->session->set_userdata('new_user_id',$directory_user_id);
                 //$this->session_user_id = $directory_user_id;

                 $login_info['email'] = $form_email;
                 $login_info['password'] = $form_password;

                 $this->session->set_userdata('login_info', $login_info);
                 
        	     redirect('register/products');
        	}

        	$data['form_email'] = $form_email;
        	$data['form_re_email'] = $form_re_email;


      }
      $data['side_left_directory'] = 1;
      $breadcrumb_list = array(
	array('name'=>'Directory', 'href'=>site_url('')),
	array('name'=>'Advertise', 'href'=>site_url('advertise')),
	);
      $data['breadcrumb_list'] = $breadcrumb_list;
      //$data['recaptcha']=$this->recaptcha->get_html();
      $data['user_info']=$this->session->userdata('user_info');
      $this->load->view(TEMPLATE_NAME.'/front/register/login_information',$data);
     
     
	}

   function products()
    {       //print_r($this->session->userdata('login_info'));exit;
      
        $submit_button = $this->input->post('submit');
        if ($submit_button != "")
        { 
            $this->form_validation->set_rules('gender', 'Gender', 'required');
                $this->form_validation->set_rules('category', 'category','required');
                $this->form_validation->set_rules('hair_color', 'Hair color','required');
                $this->form_validation->set_rules('ethnicity', 'Ethnicity','required');
                 $gender[] = $this->input->post('gender');
            $category = $this->input->post('category');
            $this->session->set_userdata('categories',$category);
            $hair_color = $this->input->post('hair_color');
            $ethnicity= $this->input->post('ethnicity');
            $data['gender'] =$gender ;
            $data['category'] = $category ;
            $data['hair_color'] = $hair_color ;
            $data['ethnicity'] =  $ethnicity ;
        	//if($this->form_validation->run() == TRUE)
           // {

          // print_r($data);
            if(!empty ($gender))
            $services = array_merge($gender);
             if(!empty ($category))
            $services = array_merge($category,$services);
             if(!empty ($hair_color))
            $services = array_merge($hair_color,$services);
             if(!empty ($ethnicity))
            $services = array_merge($ethnicity,$services);

           //print_r( $services );
            $this->session->set_userdata('products',$services);
            $other_data['height'] = $this->input->post('height');
			$other_data['weight'] = $this->input->post('weight');
			$other_data['age'] = $this->input->post('age');
			$this->session->set_userdata('products_other', $other_data);
           // $this->Directory_company_model->update_services($this->session_user_id, $services);
            $data['notification'] = "Services information updated";
           redirect('register/company');
            //}else{
            // $this->load->view(TEMPLATE_NAME . '/front/register/panel_products', $data);
           // }
        }else{
        $data['productType'] = $productType;
        $data['company_detail'] = $company_detail;
        $data['no_breadcrumb'] = 1;
        $data['services_list'] = $this->Directory_services_model->get_list_services("services");
       // print_r($data['services_list']);
         foreach($data['services_list'] as $key=>$value){
               if($value['services']=='Gender')
              { 
                 $gender[]= $value;
              }
              if($value['services']=='Category')
              {
                 $category[]= $value;
              }
              if($value['services']=='Hair Color')
              {
                 $hair_color[]= $value;
              }
              if($value['services']=='Ethnicity')
              {
                 $ethnicity[]= $value;
              }

            }
            $data['gender'] =$gender ;
            $data['category'] = $category ;
            $data['hair_color'] = $hair_color ;
            $data['ethnicity'] =  $ethnicity ;
         

        $this->load->view(TEMPLATE_NAME . '/front/register/panel_products', $data);
        }
    }

    function company()
    {  
         //sprint_r($this->session->userdata('products_other'));
      
        $data = array();

        $data['region_list']    = $this->_get_region_by_country(224);

		$data['services_list'] = $this->Directory_services_model->get_list_services("services");

        $submit_button = $this->input->post('submit');
        if ($submit_button != "")
        { 
            $this->form_validation->set_rules('name', 'Company name', 'required');
            $this->form_validation->set_rules('description', 'Company Description',
                'required');
            $this->form_validation->set_rules('contact_number', 'Telephone number',
                'required');
            /*  $this->form_validation->set_rules('physical_street', 'Physical street address',
                'required');
          $this->form_validation->set_rules('physical_suburb', 'Physical suburb address',
                'required');
            $this->form_validation->set_rules('physical_city', 'Physical city address',
                'required');*/

            //$this->form_validation->set_rules('physical_zipcode', 'Zipcode','required');
            $this->form_validation->set_rules('province_id', 'Province', 'required');
            //$this->form_validation->set_rules('city_name', 'City','required');
            $this->form_validation->set_rules('contact_email', 'email address', 'valid_email');
            if ($this->form_validation->run() == true)
            {
               
                if ($this->input->post('website') == 'http://')
                {
                    $company_website = '';
                } else
                {
                    $company_website = substr($this->input->post('website'), 7);
                }
                //$company_website = $this->input->post('website');
                $company['name'] = $this->input->post('name');
                $company['description'] = $this->input->post('description');
                $company['contact_number'] = $this->input->post('contact_number');
                $company['mobile_number'] = $this->input->post('mobile_number');
                $company['fax_number'] = $this->input->post('fax_number');
                $company['contact_person'] = $this->input->post('contact_person');
                //add province name and city name
                $company['province_id'] = $this->input->post('province_id');
                $company['city_name'] = $this->input->post('city_name');
                $company['physical_street'] = $this->input->post('physical_street');
                $company['physical_suburb'] = $this->input->post('physical_suburb');
                $company['physical_city'] = $this->input->post('physical_city');
                $company['physical_zipcode'] = $this->input->post('physical_zipcode');
                $company['postal_street'] = $this->input->post('postal_street');
                $company['postal_suburb'] = $this->input->post('postal_suburb');
                $company['postal_city'] = $this->input->post('postal_city');
                $company['postal_zipcode'] = $this->input->post('postal_zipcode');
                $company['latitude'] = $this->input->post('latitude');
                $company['longitude'] = $this->input->post('longitude');
                $company['country_name'] = $this->input->post('country_name');
                $company['contact_email'] = $this->input->post('contact_email');
                // -- company logo
                $company['company_logo'] = $this->input->post('upload');
                /*$result = $this->Directory_company_model->update_company($this->session_user_id,
                    ($company_name), $company_desc, $company_website, $contact_number, $mobile,
                    $fax_number, $contact_email, $company_logo, $province_id, $city_name);
                //echo $this->Directory_company_model->db->last_query();
                $this->Directory_company_model->update_location($this->session_user_id, $physical_street,
                    $physical_suburb, $physical_city, $physical_zipcode, $postal_street, $postal_suburb,
                    $postal_city, $postal_zipcode, $latitude, $longitude, $country_name);
                //die($this->Directory_company_model->db->last_query());
                */
                $this->session->set_userdata('company_info',$company);
               // print_r($this->session->userdata('company_info'));
                $data['messageBox'] = 'Your profile changes have been saved';
                 $this->load->model(array('Register_model'));
                    $packages_detail = $this->Register_model->get_package_offers_byId($this->session->userdata('packages'));
                if($packages_detail['cost'] < 1){
                   $directory_id =  $this->registration_process();
                   if( $directory_id) 
                     redirect('register/signup_success/'.$directory_id);
                     else                        
                     redirect(current_url());
                }

               redirect('register/payment_type');

            }
            else
            {
                $data['messageBox'] = 'Your changes failed to saved ' . validation_errors();
                $this->load->view(TEMPLATE_NAME . '/front/register/panel_company_view', $data);

            }
        }


            $company_detail = $this->Directory_company_model->get_company_by_id($this->session_user_id);

        $data['company_detail'] = $company_detail;
       // $data['country_list']   = $this->Location_model->get_country();
        //$data['region_list']    = $this->Location_model->get_region_by_country(224);
        $data['no_breadcrumb']  = 1;
        //echo "<pre><font color='#999999'>";print_r($data); echo "</font></pre>";
        $this->load->view(TEMPLATE_NAME . '/front/register/panel_company_view', $data);
    }
function payment_type(){
    
  // print_r($this->session->userdata('categories'));die();
        if(isset($_POST['submit_payment_x']) || isset($_POST['submit_payment']))
		{
                         
       $paymentType = $this->input->post('payment_type');
       $this->session->set_userdata('payment_type',$paymentType);
        $user_detail = $this->session->userdata('user_info');
                    
                   $name = $user_detail['name'];
                     $company = $user_detail['company'];
                    $telephone = $user_detail['telephone'];
                    $email = $user_detail['email'];
                    $this->load->model(array('Register_model'));
                    $packages_detail = $this->Register_model->get_package_offers_byId($this->session->userdata('packages'));
                 
                    $payfor = $packages_detail['package_type'];
                    $country = 'US';
                    $amount = $packages_detail['cost'];
                    $categories = $this->session->userdata('categories'); //print_r($this->session->userdata('categories'));//die();
                    $cnt_cat = count($categories);
                   if($cnt_cat > 1){
                        $cat_times = $cnt_cat-1;
                        $amount = $amount+ (20* $cat_times);
                        
                    }
                    $arr = array('name' => $name,'companyName' => 'customer','telephone' =>$telephone,'email' =>$email,'payfor' =>$payfor,'country' => $country, 'amount' => $amount, 'paymentType' => $paymentType);
                       
                if($paymentType == 1)
                {
                    $this->load->view(TEMPLATE_NAME."/front/register/make_a_payment_creditcard_view",$arr);

                }
                else
                { $this->load->model(array('make_a_payment_model'));
                    $data['bankdetails'] = $this->make_a_payment_model->getBAnkDetails();
                    
                    $orderid = $this->make_a_payment_model->insertpayment($arr);
                   // $this->session->set_userdata('register_message', "");

                    
                    //$directory_user_id = $this->registration_process();
                   // if($directory_user_id)
                       $data['payment_confirm'] = "Thank you for placing your ads on Kyprisguide.com. Please print this invoice and mail it along with your payment (<a href='javascript:void(0)' onclick='return window.print();'>print</a>)";

                    $this->make_a_payment_model->sendemailBybanktype($orderid);
                     $data = array_merge($data,$arr);    
                    $this->load->view(TEMPLATE_NAME."/front/register/make_a_payment_banktransfer_view",$data);

                }
			}
			else
			{
				//unset($data);
                //$data['recaptcha']=$this->recaptcha->get_html();


            $this->load->view(TEMPLATE_NAME."/front/register/make_a_payment_view",$data);
           // redirect('register/make_a_payment_view');
        }



}
function payment()
    { 
      
    
        $this->load->model('make_a_payment_model');

        if(isset($_POST['submit_payment_x']) || isset($_POST['submit_payment']))
		{
                
                $this->_confirmpayemnt();
                }else
                    {
				//unset($data);
                //$data['recaptcha']=$this->recaptcha->get_html();


            $this->load->view(TEMPLATE_NAME."/front/register/make_a_payment_view",$data);
           // redirect('register/make_a_payment_view');
            }
    }

    function _confirmpayemnt()
    { //redirect(register/categories);
        $this->load->model('make_a_payment_model');
         $user_detail = $this->session->userdata('user_info');
         $paymentType = $this->session->userdata('payment_type');
                $name = $user_detail['name'];
                  // $company = $user_detail['company'];
                    $telephone = $user_detail['telephone'];
                    $email = $user_detail['email'];
                    $this->load->model(array('Register_model'));
                    $packages_detail = $this->Register_model->get_package_offers_byId($this->session->userdata('packages'));
                 
                    $payfor = $packages_detail['package_type'];
                    $country = 'US';
                    $amount = $packages_detail['cost'];
                    $categories = $this->session->userdata('categories'); 
                     $cnt_cat = count($categories);
                    if($cnt_cat > 1){
                        $cat_times = $cnt_cat-1;
                        $amount = $amount+ (20* $cat_times);
                        
                    }
                    $arr = array('name' => $name,'companyName' => 'customer','telephone' =>$telephone,'email' =>$email,'payfor' =>$payfor,'country' => $country, 'amount' => $amount, 'paymentType' => $paymentType);
                       // $data = array_merge($data,$arr);
        

        $orderid = $this->make_a_payment_model->insertpayment($arr);
        // $this->session->set_userdata('register_message',"Thank you for placing your ads on Kyprisguide.com. You can manage your ads at (link to advertiser management panel)");
 
         $directory_id =  $this->registration_process();
                   if( $directory_id)
                     redirect('register/signup_success/'.$directory_id);
                     else                        
                     redirect(current_url());
                     
        set_time_limit(100);

//        //$paymentType =urlencode( $_POST['paymentType']);
//         $firstName =urlencode( $_POST['firstName']);
//         $lastName =urlencode( $_POST['lastName']);
//         $creditCardType =urlencode( $_POST['creditCardType']);
//         $creditCardNumber = urlencode($_POST['creditCardNumber']);
//         $expDateMonth =urlencode( $_POST['expDateMonth']);
//
//         $expDateYear =urlencode( $_POST['expDateYear']);
//         $cvv2Number = urlencode($_POST['cvv2Number']);
//         $budget=$_POST['radio'];
//
//    	if(isset($_POST['radio'])== 1)
//   		{
//
//            $budgetperiod=$_POST['budgetPeriod'];
//         }
//         else
//         {
//            $budgetperiod="";
//         }
//
//         //$URL = "https://www.mygate.co.za/enterprise/3x0x0/ePayService.cfc?wsdl";
//
//        $Mode = "0";
//        $MerchantID = "79958a8d-0c7b-4038-8e2e-8948e1d678e1";
//        $ApplicationID = "4b775479-a264-444c-b774-22d5521852d8";
//
//        $MerchantRef = "Inv0001";
//        $InvTotal = $amount;
//        $Currency = "ZAR";
//
//        $CreditCard = $creditCardNumber;
//        $CardHolder = $firstName.' '.$lastName;
//        $CVC = $cvv2Number;
//        $ExpMonth = $expDateMonth;
//        $ExpYear = $expDateYear;
//        $CardType = $creditCardType;
//
//        //A U T H O R I S E  P U R C H A S E     (A C T I O N  =  1)
//        $client = new SoapClient($URL);
//        $arrResults = $client->fProcess(
//        'fnblive', 			//Gateway
//        $MerchantID,  		//MerchantID
//        $ApplicationID, 	//ApplicationID
//        '1',				//Action
//        '',					//TransactionIndex
//        'MyGate',			//Terminal
//        $Mode,				//Mode
//        $MerchantRef,		//MerchantReference
//        $InvTotal,			//Amount
//        $Currency,			//Currency
//        '',					//CashBackAmount
//        $CardType,			//CardType
//        '',					//AccountType
//        $CreditCard,		//CardNumber
//        $CardHolder,		//CardHolder
//        $CVC,				//CCVNumber
//        $ExpMonth,			//ExpiryMonth
//        $ExpYear,			//ExpiryYear
//        $budget,			//Budget
//        $budgetperiod,		//BudgetPeriod
//        '',					//AuthorizationNumber
//        '',					//PIN
//        '',					//DebugMode
//        '06',				//eCommerceIndicator
//        '',					//verifiedByVisaXID
//        '',					//verifiedByVisaCAFF
//        '',					//secureCodeUCAF
//        '',					//Unique Client Index - this is used to uniquely identify the client and is used by the MyGate Fraud module. It is an optional parameter. Please see online documentation for details.
//        '',					//IP Address - this is the IP address of the user using the online gateway (retrieved by yourselves), and is used by the MyGate Fraud module. It is an optional parameter.	 Please see online documentation for details.
//        ''					//Shipping Country Code - this is the 2-digit shipping country code of the user, and is used by the MyGate Fraud module. It is an optional parameter. Please see online documentation for details.
//        );
//
//        //P U R C H A S E     (A C T I O N  =  3)
//        list($ResultName, $ResultValue) = explode("||",$arrResults[0]);
//        if ($ResultValue = 0)
//        {
//        	list($ResultName, $ResultValue) = explode("||",$arrResults[1]);
//        	$arrResults = $client->fProcess(
//        	'fnblive', 			//Gateway
//        	$MerchantID,  		//MerchantID
//        	$ApplicationID, 	//ApplicationID
//        	'3',				//Action
//        	$ResultValue,		//TransactionIndex
//        	'',					//Terminal
//        	'',					//Mode
//        	'',					//MerchantReference
//        	'',					//Amount
//        	'',					//Currency
//        	'',					//CashBackAmount
//        	'',					//CardType
//        	'',					//AccountType
//        	'',					//CardNumber
//        	'',					//CardHolder
//        	'',					//CCVNumber
//        	'',					//ExpiryMonth
//        	'',					//ExpiryYear
//        	'',					//Budget
//        	'',					//BudgetPeriod
//        	'',					//AuthorizationNumber
//        	'',					//PIN
//        	'',					//DebugMode
//        	'',					//eCommerceIndicator
//        	'',					//verifiedByVisaXID
//        	'',					//verifiedByVisaCAFF
//        	''					//secureCodeUCAF
//        	);
//        	list($ResultName, $ResultValue) = explode("||",$arrResults[0]);
//        	if ($ResultValue = 0)
//        	{
//
//        	$formStr = "<html>";
//        	$formStr .="<head>";
//        	$formStr .="<title>".'Mykprisguide'."</title>";
//        	$formStr .="</head>";
//        	$formStr .="<body>";
//        	$formStr .="<form name=\"getBackWithDetailsFromPaypal\" id=\"getBackWithDetailsFromPaypal\" method=\"POST\" enctype=\"multipart/form-data\" action=\"".site_url()."make-a-payment/paymentsuccess\">";
//        	$formStr .="<input type=\"hidden\" name=\"orderid\" value=\"".$orderid."\"/>";
//        	$formStr .="<input type=\"hidden\" name=\"transID\" value=\"".$MerchantID."\" />";
//        	$formStr .="<input type=\"hidden\" name=\"transactionType\" value=\"direct\" />";
//        	$formStr .="</form>";
//        	$formStr .="<script type=\"text/javascript\">document.getElementById('getBackWithDetailsFromPaypal').submit();</script>";
//        	$formStr .="</body>";
//        	$formStr .="</html>";
//
//        	echo $formStr;
//
//        		//echo("<br />");
//        		//echo("Successful Authorization <br />");
//        		//list($ResultName, $ResultValue) = explode("||",$arrResults[0]);
//        		//echo($ResultValue);
//        		//echo("<br />");
//        	}
//        	else
//        	{
//        	$formelements .="<head>";
//        	$formelements .="<title>Mykprisguide</title>";
//        	$formelements .="</head>";
//        	$formelements .="<body>";
//        	$formelements .="
//        				<form name=\"frmfailure\" id=\"frmfailure\" action=\"".site_url()."make-a-payment/paymentfail\" METHOD=\"post\" >
//        				<input type=\"hidden\" name=\"firstName\" value='".$_POST['firstName']."' />
//        				<input type=\"hidden\" name=\"lastName\" value='".$_POST['lastName']."' />
//        				<input type=\"hidden\" name=\"orderid\" value='".$orderid."'/>
//        				<input type=\"hidden\" name=\"country\" value='".$_POST['country']."' />
//        				<input type=\"hidden\" name=\"city\" value='".$_POST['city']."' />
//        				<input type=\"hidden\" name=\"address\" value='".$_POST['address']."' />
//        				<input type=\"hidden\" name=\"zip\" value='".$_POST['zip']."' />
//        				<input type=\"hidden\" name=\"creditCardType\" value='".$_POST['creditCardType']."' />
//        				<input type=\"hidden\" name=\"creditCardNumber\" value='".$_POST['creditCardNumber']."' />
//        				<input type=\"hidden\" name=\"expDateMonth\" value='".$_POST['expDateMonth']."' />
//        				<input type=\"hidden\" name=\"expDateYear\" value='".$_POST['expDateYear']."' />
//        				<input type=\"hidden\" name=\"cvv2Number\" value='".$_POST['cvv2Number']."' />
//        				<input type=\"hidden\" name=\"amount\" value='".$_POST['amount']."' />
//        				<input type=\"hidden\" name=\"error\" value=\"Failed Authorization\" />
//        				</form>
//        				";
//        				$formelements .="<script type=\"text/javascript\">document.getElementById('frmfailure').submit();</script>";
//        	$formelements .="</body>";
//        	$formelements .="</html>";
//        	echo $formelements;
//
//        	}
//        }
//        else
//        {
//        	$formelements .="<head>";
//        	$formelements .="<title>Mykprisguide</title>";
//        	$formelements .="</head>";
//        	$formelements .="<body>";
//        	$formelements .="
//        				<form name=\"frmfailure\" id=\"frmfailure\" action=\"".site_url()."make-a-payment/paymentfail\" METHOD=\"post\" >
//        				<input type=\"hidden\" name=\"firstName\" value='".$_POST['firstName']."' />
//        				<input type=\"hidden\" name=\"lastName\" value='".$_POST['lastName']."' />
//        				<input type=\"hidden\" name=\"orderid\" value=\"".$orderid."\"/>
//        				<input type=\"hidden\" name=\"country\" value='".$_POST['country']."' />
//        				<input type=\"hidden\" name=\"city\" value='".$_POST['city']."' />
//        				<input type=\"hidden\" name=\"address\" value='".$_POST['address']."' />
//        				<input type=\"hidden\" name=\"zip\" value='".$_POST['zip']."' />
//        				<input type=\"hidden\" name=\"creditCardType\" value='".$_POST['creditCardType']."' />
//        				<input type=\"hidden\" name=\"creditCardNumber\" value='".$_POST['creditCardNumber']."' />
//        				<input type=\"hidden\" name=\"expDateMonth\" value='".$_POST['expDateMonth']."' />
//        				<input type=\"hidden\" name=\"expDateYear\" value='".$_POST['expDateYear']."' />
//        				<input type=\"hidden\" name=\"cvv2Number\" value='".$_POST['cvv2Number']."' />
//        				<input type=\"hidden\" name=\"amount\" value='".$_POST['amount']."' />
//        				<input type=\"hidden\" name=\"error\" value=\"Failed Authorization\" />
//        				</form>
//        				";
//        				$formelements .="<script type=\"text/javascript\">document.getElementById('frmfailure').submit();</script>";
//        	$formelements .="</body>";
//        	$formelements .="</html>";
//        	echo $formelements;
//
//            }
    }

    function paymentfail()
    {
        $this->load->model('make_a_payment_model');

        $this->make_a_payment_model->deletepaymentfail();

        $this->load->view(TEMPLATE_NAME."/front/make_a_paymentfail_view");
    }

    function paymentsuccess()
    {
        $this->load->model('make_a_payment_model');

        $arr = array('transaction_id ' => $this->input->post('transID'),'pay_status' => '1');

        $cond = array('id' => $this->input->post('orderid'));

        $this->make_a_payment_model->updatepaymentsuccess($arr,$cond);

        //$this->make_a_payment_model->sendemailBybanktype($this->input->post('orderid'));
        

        $this->load->view(TEMPLATE_NAME."/front/make_a_paymentsuccess_view");
    }

    function check_captcha($val)
    {

        $result = $this->recaptcha->check_answer($_SERVER["REMOTE_ADDR"],$this->input->post('recaptcha_challenge_field'),$val);
        if ($result) {
            return true;
        } else {
            $this->form_validation->set_message('check_captcha','Incorrect Security Image Response');
            return false;
        }

    }

    function check_email($val)
    {
        if (!$this->Directory_user_model->check_available_email($val, $this->
            session_user_id))
        {
            $this->form_validation->set_message('check_email', '%s ' . $val .
                ' is already on our system, please use another %s');
            return false;
        } else
        {
            return true;
        }
    }
    function check_ssl()
    {
        if ($_SERVER['HTTPS'] != "on")
        {
            $url = "https://" . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
            header("Location: $url");
            exit;
        }
    }
    
    function registration_process(){
         $login_detail = $this->session->userdata('login_info');//print_r($login_detail);exit;
         if(!empty($login_detail)){
    $form_email = $login_detail['email'];
     $form_password = $login_detail['password'];
     $company_detail = $this->session->userdata('company_info');//print_r($company_detail);
   
     $company_name = $company_detail['name'];
      $company_desc  = $company_detail['description'];
     // $company_website  = $company_detail[''];
       $contact_number = $company_detail['contact_number'];
       $mobile   = $company_detail['mobile_number'];
       $fax_number   = $company_detail['fax_number'];
        $contact_email   = $company_detail['contact_email'];
        $company_logo  = $company_detail['company_logo'];
         $province_id  = $company_detail['province_id'];
        $city_name  = $company_detail['city_name'];
            $physical_street  = $company_detail['physical_street'];
          $physical_suburb  = $company_detail['physical_suburb'];
          $physical_city  = $company_detail['physical_city'];
          $physical_zipcode  = $company_detail['physical_zipcode'];
          $postal_street  = $company_detail['postal_street'];
          $postal_suburb  = $company_detail['physical_suburb'];
          $postal_city  = $company_detail['postal_city'];
          $postal_zipcode  = $company_detail['postal_zipcode'];
          $latitude  = $company_detail['$latitude'];
          $longitude  = $company_detail['$longitude'];
          $country_name = $company_detail['country_name'];
      $products_detail = $this->session->userdata('products');//print_r($products_detail);die();
      $services = $products_detail;    
    
    $directory_user_id = $this->Directory_company_model->register_user($form_email, $form_password);
    $this->session->set_userdata('new_user_id',$directory_user_id);
    $this->session_user_id = $directory_user_id;
     $this->Directory_company_model->update_services($this->session_user_id, $services);
     
        $others = $this->session->userdata('products_other');
		if($others){
                    $height = $others['height'];
		  $weight = $others['weight'];
		  $age = $others['age'];
                }
      $result = $this->Directory_company_model->update_company($this->session_user_id,
                    $company_name, $company_desc, $company_website, $contact_number, $mobile,
                    $fax_number, $contact_email, $company_logo, $province_id, $city_name, $height, $weight, $age);
                //echo $this->db->last_query(); exit;
                $this->Directory_company_model->update_location($this->session_user_id, $physical_street,
                    $physical_suburb, $physical_city, $physical_zipcode, $postal_street, $postal_suburb,
                    $postal_city, $postal_zipcode, $latitude, $longitude, $country_name);
                //die($this->Directory_company_model->db->last_query());
//ADDED BY SUBIN
$packages_id = $this->session->userdata('packages');
$result = $this->packages_model->update_directory_package_list($this->session_user_id,$packages_id);
//               $this->session->unset_userdata('login_info');
//                $this->session->unset_userdata('company_info');
//                $this->session->unset_userdata('products');
            
           // $this->success_notification($directory_user_id);
             
                return $directory_user_id;
                }else{
                    redirect('register');
                }
        
    }
     function signup_success(){
    	 $directory_user_id = $this->uri->segment(3);//die();
    	$directory_user = $this->Directory_user_model->get_detail($directory_user_id);
       $data['user_email'] = $directory_user['email'];//die();
    	$submit_button = $this->input->post('submit');
     	if($submit_button == "resend"){
    		//$this->Directory_company_model->register_user($this->directory_user_email, $this->directory_user_password);
    		$activation_link = $this->Directory_company_model->generate_activation_data($directory_user['email'], $directory_user['password_real']);
    		$this->Directory_company_model->send_activation_email($directory_user['email'], '',$activation_link['link']);
     	}elseif($submit_button == "update"){
    		$form_email = $this->input->post('email');
    		$this->form_validation->set_rules('email', 'Email ', 'required|valid_email|callback_check_email');
    		if($this->form_validation->run() == TRUE){
    			$this->Directory_user_model->update_email($form_email, $directory_user_id);
    			$activation_link = $this->Directory_company_model->generate_activation_data($directory_user['email'], $directory_user['password_real']);
    			$this->Directory_company_model->send_activation_email($form_email, '',$activation_link['link']);
    			//$this->Directory_company_model->register_user($form_email, $this->directory_user_password);
    		}
     	}elseif($directory_user_id){
     	  	$directory_user = $this->Directory_user_model->get_detail($directory_user_id);
            $data['user_email'] = $directory_user['email'];
        		$activation_link = $this->Directory_company_model->generate_activation_data($directory_user['email'], $directory_user['password_real']);
        		$this->Directory_company_model->send_activation_email($directory_user['email'], '',$activation_link['link']);
     	}
     	$data['directory_user_id'] = $directory_user_id;
     	$breadcrumb_list = array(
			array('name'=>'register', 'href'=>site_url('')),
			array('name'=>'Sign Up Success', 'href'=>site_url('signup_success/'.$directory_user_id))
		);
      	$data['breadcrumb_list'] = $breadcrumb_list;
     	//echo "<pre><font color='#999999'>";print_r($_POST); echo "</font></pre>";
     	//echo "<pre><font color='#999999'>";print_r($directory_user); echo "</font></pre>";
     	//$data['region_list']    = $this->_get_region_by_country(224);
		 
		 //$data['services_list'] = $this->Directory_services_model->get_list_services("services");
		 
      	$this->load->view(TEMPLATE_NAME.'/front/register/signup_success', $data);
    }
    
    function success_notification($directory_user_id=''){
         if(directory_user_id=='')
         $directory_user_id = $this->uri->segment('3');
   
    if(directory_user_id==''){
         redirect('register');
        }else{
        	//$directory_user_id = $this->uri->segment(3);
        	$directory_user = $this->Directory_user_model->get_detail($directory_user_id);
            $data['user_email'] = $directory_user['email'];
        	$submit_button = $this->input->post('submit');
         	if($submit_button == "resend"){
        		$this->Directory_company_model->register_user($this->directory_user_email, $this->directory_user_password);
        		$activation_link = $this->Directory_company_model->generate_activation_data($directory_user['email'], $directory_user['password_real']);
        		$this->Directory_company_model->send_activation_email($directory_user['email'], '',$activation_link['link']);
         	}
        	if($submit_button == "update"){
        		$form_email = $this->input->post('email');
        		$this->form_validation->set_rules('email', 'Email ', 'required|valid_email|callback_check_email');
        		if($this->form_validation->run() == TRUE){
        			$this->Directory_user_model->update_email($form_email, $directory_user_id);
        			$activation_link = $this->Directory_company_model->generate_activation_data($directory_user['email'], $directory_user['password_real']);
        			$this->Directory_company_model->send_activation_email($form_email, '',$activation_link['link']);
        			$this->Directory_company_model->register_user($form_email, $this->directory_user_password);
        		}
         	}
         	$data['directory_user_id'] = $directory_user_id;
             redirect('register/signup_success');
         }
    }

   


     function _get_region_by_country($country_id){
     $this->db->where('adm1code =', 'kyp');
     $this->db->order_by('name');
     $query = $this->db->get('region');
    return $query->result_array();
  }
   }